using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Firefly;
using Ether;

namespace Guardian
{
    public static class GameFlags
    {
        public static bool DrawWireframe = false;
        public static bool Editor_Flag = false;
    }

    public class Launcher : Microsoft.Xna.Framework.Game
    {
        //Fields
        private KeyboardState last;
        public ScreenManager Manager;

        //Construct
        public Launcher()
        {
            Content.RootDirectory = "Content";
            Manager = new ScreenManager(this, "data/config.cfg");
        }

        protected override void Initialize()
        {
            this.IsMouseVisible = true;
            this.Window.Title = "Guardians of the Ether " + EtherEngine.Version;

            Manager.FPSFontColor = Color.Red;
            Manager.AddMenuScreen(MainMenu.Key, new MainMenu(this), true);
            Manager.AddGameScreen(RenderTest01.Key, new RenderTest01(this));
            Manager.AddGameScreen(RenderTest02.Key, new RenderTest02(this));
            Manager.AddGameScreen(RenderTest03.Key, new RenderTest03(this));


            base.Initialize(); 
        }
        protected override void LoadContent()
        {
            Ether.Libs.Resources.LoadData(this);
            Manager.LoadScreenManager();           
        }
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.F9) && last.IsKeyUp(Keys.F9))
                GameFlags.DrawWireframe = !GameFlags.DrawWireframe;
            
            Manager.UpdateScreens(gameTime);
            last = Keyboard.GetState();

            base.Update(gameTime);
        }
        protected override void Draw(GameTime gameTime)
        {
            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            rs.FillMode = (GameFlags.DrawWireframe) ? FillMode.WireFrame : FillMode.Solid;
            
            DepthStencilState dss = new DepthStencilState();
            dss.DepthBufferEnable = true; 
            
            GraphicsDevice.RasterizerState = rs;
            GraphicsDevice.DepthStencilState = dss;
            
            GraphicsDevice.Clear(EtherEngine.BackgroundColor);

            Manager.RenderScreens(gameTime);

            base.Draw(gameTime);
        }
    }
}
